<?php

namespace app\admin\listener\log;

class KeywordFilter implements FilterInterface
{
    protected array $sensitiveKeywords;
    public function __construct()
    {
        $this->sensitiveKeywords = config('filter.sensitive_keywords', []);
    }

    public function apply(array &$data): void
    {
        if (empty($this->sensitiveKeywords)) {
            return;
        }

        foreach ($data as $key => &$value) {
            foreach ($this->sensitiveKeywords as $keyword) {
                if (stripos($key, $keyword) !== false) {
                    $value = '******';
                    continue 2;
                }
            }
        }
        unset($value);
    }
}